package com.imooc.course6

/*
 * @Author Wangjin
 * @Date 2019-03-05
 * @Email wangjin4901@vip.qq.com
 */

object ListApp extends App{
  val l = List(1,2,3,4,5)
  l.head // 除了第一个元素是head

  l.tail // 其他都是tail

  val l2 = 1 :: Nil // 1为head Nil为tail 拼接成List

  val l3 = 2 :: l2

  val l4 = 1 :: 2 :: 3 :: Nil

  val l5 = scala.collection.mutable.ListBuffer[Int]()

  l5 += 2

  l5 ++= Array(2,3,4,5)

  l5 -= 2

  l5 -= (1, 4)


  println(l5)

  println(l5.toArray.mkString)

  println(l5.isEmpty)

  l5.head

  l5.tail

  l5.tail.head


  def sum (nums: Int*): Int = {
    if (nums.isEmpty) {
      0
    } else {
      nums.head + sum(nums.tail: _*) // 固定写法 转换为可变数组
    }
  }

  println(sum())

  println(sum(1,2,3,4,5,6))
}
